home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 41
/
Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso
/
-seriously_amiga-
/
graphics
/
ifx_antique
/
antique.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-04-19
|
6KB
|
208 lines
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <utility/tagitem.h>
#include <powerup/ppclib/interface.h>
#include <powerup/ppclib/message.h>
#include <powerup/ppclib/tasks.h>
#include <powerup/proto/ppc.h>
#include <PowerUP/PPCLib/object.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <scan/hooks.h>
#include <stdio.h>
/* This information is required by the "start.o" startup code. */
char *HookName = "Antique PPC";
/* A version string so the Version command works on us. */
char *HookVersion = "\0$VER: Antique PPC 1.0.0 (12.09.98)";
char *HookText = "Hook_Antique_PPC";
int HookTextCount = 0;
char **HookStrings[] = { NULL };
struct StartupData
{
ULONG MsgCount;
};
void hook_main (int argc, char **argv)
{
struct Buffer *buf;
int le, te;
UBYTE *red, *grn, *blu;
struct Library *PPCLibBase;
struct TagItem MyTags[10];
void *PPCPort;
void *ReplyPort;
void *StartupMsg;
void *M68kMsg;
void *PPCMsg;
void *ElfObject;
void *Task;
ULONG *Body;
struct StartupData *StartupData;
ULONG i;
ULONG w,h;
extern char elfobject[];
extern size_t elfobject_size;
/*
* Get current buffer.
*/
if (ScanBase->sb_AreaTool == AT_BRUSH)
buf = ScanBase->sb_Brush;
else
buf = ScanBase->MainBuffer;
/*
* If no buffer, complain and exit.
*/
if (!buf) {
SetError(ERR_NoBuffer);
Error();
return;
}
/*
* Get area to be affected. If the user has defined a region,
* then the Buffer->Mask structure defines that region. We
* limit our processing to that region.
*/
if (buf->Mask) {
le = buf->Mask->OffsetX;
te = buf->Mask->OffsetY;
w = buf->Mask->Width;
h = buf->Mask->Height;
}
else {
le = 0;
te = 0;
w = buf->Width;
h = buf->Height;
}
if (PPCLibBase = OpenLibrary("ppc.library", 44))
{
if( ElfObject = PPCLoadObjectTags( PPCELFLOADTAG_ELFADDRESS, (ULONG)elfobject,
PPCELFLOADTAG_ELFLENGTH, (ULONG)elfobject_size,
TAG_DONE ) )
{
MyTags[0].ti_Tag = TAG_DONE;
if (ReplyPort = PPCCreatePort(MyTags))
{
if (StartupMsg = PPCCreateMessage(ReplyPort, 0))
{
if (StartupData = PPCAllocVec(sizeof(struct StartupData), MEMF_ANY))
{
StartupData->MsgCount = h;
MyTags[0].ti_Tag = PPCTASKTAG_STARTUP_MSG;
MyTags[0].ti_Data =(ULONG) StartupMsg;
MyTags[1].ti_Tag = PPCTASKTAG_STARTUP_MSGDATA;
MyTags[1].ti_Data =(ULONG) StartupData;
MyTags[2].ti_Tag = PPCTASKTAG_STARTUP_MSGLENGTH;
MyTags[2].ti_Data = 0;
MyTags[3].ti_Tag = PPCTASKTAG_STARTUP_MSGID;
MyTags[3].ti_Data = 0;
MyTags[4].ti_Tag = PPCTASKTAG_MSGPORT;
MyTags[4].ti_Data = TRUE;
MyTags[5].ti_Tag = PPCTASKTAG_NAME;
MyTags[5].ti_Data = (ULONG)HookName;
MyTags[6].ti_Tag = TAG_DONE;
if (Task = PPCCreateTask(ElfObject, MyTags))
{
if (PPCPort=(void*) PPCGetTaskAttrsTags(Task,
PPCTASKINFOTAG_MSGPORT,0,
TAG_END))
{
if (Body = PPCAllocVec(sizeof(ULONG)*5, MEMF_PUBLIC))
{
if (PPCMsg = PPCCreateMessage(ReplyPort, sizeof(TEXT)))
{
Body[2] = (ULONG)w;
Body[3] = (ULONG)le;
/*
* Save the region we are about to fiddle with into an undo buffer.
*/
SaveUndo(buf, le, te, w, h);
/*
* Start a cancel-able status bar.
*/
BeginBar("Antique PPC", h, TRUE);
for (i=0;i<h;i++)
{
if (Bar(i)) {
/* Status bar was cancelled if Bar() returns non-zero */
RestoreUndo(FALSE); /* restore portion that was already
modified from the undo buffer */
break;
}
if (!GetBufLine(buf, &red, &grn, &blu, i + te)) {
/* Failure means a vmem disk fault of some kind */
break;
}
Body[0] = (ULONG)grn;
Body[1] = (ULONG)blu;
PPCSendMessage(PPCPort,
PPCMsg,
Body,
sizeof(ULONG)*5,
0x12345678);
PPCWaitPort(ReplyPort);
PPCGetMessage(ReplyPort);
PutBufLine(buf);
}
for (;;)
{
if ((M68kMsg=PPCGetMessage(ReplyPort)) == StartupMsg)
{
break;
}
else
{
PPCWaitPort(ReplyPort);
}
}
PPCDeleteMessage(PPCMsg);
}
PPCFreeVec(Body);
}
}
}
PPCFreeVec(StartupData);
}
PPCDeleteMessage(StartupMsg);
}
PPCDeletePort(ReplyPort);
}
PPCUnLoadObject(ElfObject);
}
CloseLibrary(PPCLibBase);
}
EndBar(NULL);
RedrawFull();
}